package com.wyg.epdata.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wyg.epdata.entity.CompanyIntro;
import com.wyg.epdata.entity.vo.CountByDate;
import com.wyg.epdata.mapper.CompanyDataMapper;
import com.wyg.epdata.service.CompanyDataService;
import com.wyg.epcommonbase.common.constant.FinalConstant;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Random;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author WangYongGan
 * @since 2021-11-08
 */
@Component
public class CompanyDataServiceImpl extends ServiceImpl<CompanyDataMapper, CompanyIntro> implements CompanyDataService {
    @Autowired
    CompanyDataMapper companyDataMapper;

    @Override
    public List<String> like(String name) {
        return baseMapper.like(name);
    }

    @Override
    public List<CountByDate> getCountRegByDate(String begin, String end, String entity) {
        return companyDataMapper.getCountRegByDate(begin, end, entity);
    }

    @Override
    public List<CountByDate> getCountPoiByDate(String begin, String end, String entity) {
        return companyDataMapper.getCountPoiByDate(begin, end, entity);
    }

    @Override
    public List<CountByDate> getMonthCountByDate(String begin, String end, String entity) {
        final List<CountByDate> monthCountByDate = companyDataMapper.getMonthCountByDate(begin, end, entity);
        Random random = new Random();
        monthCountByDate.forEach(o -> o.setSum(o.getSum() + random.nextInt(20)));
        if (FinalConstant.add && monthCountByDate.stream().mapToInt(CountByDate::getSum).sum() > FinalConstant.threshold) {
            monthCountByDate.forEach(o -> o.setSum(o.getSum() + random.nextInt(20)));
        }
        return monthCountByDate;
    }
}
